/** 设置或更新token */
export const setToken = (token) => localStorage.setItem("token", token);

/** git token */
const getTkByCookie = function (name) {
  let strCookies = document.cookie;
  // 截取变成cookie数组
  const array = strCookies.split(";");
  // 循环每个cookie

  for (let i = 0; i < array.length; i++) {
    // 将cookie截取成两部分
    const item = array[i].split("=");

    // 判断cookie的name 是否相等
    if (item[0] === name) {
      setToken(item[1]);
      return item[1];
    }
  }
  return "";
};
/** 获取token */
export const getToken = () =>
  localStorage.getItem("token") || getTkByCookie("token");

export const getStudioToken = () => localStorage.getItem("accessToken");

/** 删除token */
export const delToken = () => {
  localStorage.removeItem("token");
};
